package com.example.hospitalsystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.hospitalsystem.pojo.dto.registration.UpdateBalanceDTO;
import com.example.hospitalsystem.pojo.entity.Doctor;
import com.example.hospitalsystem.pojo.entity.Patient;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface PatientMapper extends BaseMapper<Patient> {

    @Update("update patient set balance = balance - #{registrationFee} where balance > 0 and patient_id = #{patientId}")
    int updateBalanceForRegistrationFee(UpdateBalanceDTO updateBalanceDTO);

    @Update("update patient set balance = balance - #{unitPrice} where balance > 0 and patient_id = #{patientId}")
    int updateBalanceForMedicine(UpdateBalanceDTO updateBalanceDTO);

    @Select("select * from patient where patient_name = #{patientName}")
    Patient selectByName(String patientName);

    @Select("select * from patient where patient_name like concat('%',#{key},'%')")
    List<Patient> search(String key);
}
